package org.dromara.business.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.business.service.AppUserService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.business.domain.vo.AppUserVo;
import org.dromara.business.domain.bo.AppUserBo;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 钱包用户
 *
 * @author Eric
 * @date 2025-09-05
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/business/appuser")
public class AppUserController extends BaseController {

    private final AppUserService appUserService;

    /**
     * 查询钱包用户列表
     */
    @SaCheckPermission("business:appuser:list")
    @GetMapping("/list")
    public TableDataInfo<AppUserVo> list(AppUserBo bo, PageQuery pageQuery) {
        return appUserService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出钱包用户列表
     */
    @SaCheckPermission("business:appuser:export")
    @Log(title = "钱包用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(AppUserBo bo, HttpServletResponse response) {
        List<AppUserVo> list = appUserService.queryList(bo);
        ExcelUtil.exportExcel(list, "钱包用户", AppUserVo.class, response);
    }

    /**
     * 获取钱包用户详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("business:appuser:query")
    @GetMapping("/{id}")
    public R<AppUserVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(appUserService.queryById(id));
    }
}
